package com.ruoyi.quartz.task;

import com.ruoyi.stock.service.IStockSectorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Component("kplTask")
public class KplTask {

    @Autowired
    private IStockSectorService iStockSectorService;

    public void ryNoParams(String date)
    {
        System.out.println("指定日期："+date);
        LocalDate currentDate = LocalDate.now();
        int count = 0;
        System.out.println("最近100个工作日（从今天开始往前，排除周末）：");
        for (int i = 0; count < 100; i++) {
            LocalDate targetDate = currentDate.minusDays(i);
            // 检查是否是工作日（周一到周五）
            if (targetDate.getDayOfWeek() != DayOfWeek.SATURDAY &&
                    targetDate.getDayOfWeek() != DayOfWeek.SUNDAY) {
                System.out.println(targetDate);
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                iStockSectorService.batchInsert(formatter.format(targetDate));
                count++;
            }
        }
    }
}
